package GUI;

import javax.swing.*;
import java.awt.*;
import javax.swing.JScrollPane;
import javax.swing.BorderFactory;
import javax.swing.border.TitledBorder;
import java.awt.Font;
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;



public class RestauranteGrafico {

	private JFrame jFramePrinc = null;  //  @jve:decl-index=0:visual-constraint="7,7"
	private JPanel jPanelPrinc = null;
	private JLabel tituloRes = null;
	private JPanel panelCentral = null;
	private JPanel panelBoton = null;
	private JButton botonCarta = null;
	private JButton botonReserva = null;
	private JButton botonFacturacion = null;
	private JPanel panelSalir = null;
	private JButton botonSalir = null;
	private JTextArea textoEstado = null;
	public JFrame frameRestaurante = null;
	private JScrollPane scrollEstado = null;
	private JButton botonBalance = null;

	public RestauranteGrafico() {
		frameRestaurante = getJFramePrinc();
		frameRestaurante.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frameRestaurante.setVisible(true);
		frameRestaurante.setLocationRelativeTo(null);
	}







	/**
	 * This method initializes jFramePrinc
	 *
	 * @return javax.swing.JFrame
	 */
	private JFrame getJFramePrinc() {
		if (jFramePrinc == null) {
			jFramePrinc = new JFrame();
			jFramePrinc.setSize(new Dimension(400, 400));
			jFramePrinc.setTitle("Restaurante \"Donde Sea\"");
			jFramePrinc.setContentPane(getJPanelPrinc());
			jFramePrinc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		}
		return jFramePrinc;
	}

	/**
	 * This method initializes jPanelPrinc
	 *
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanelPrinc() {
		if (jPanelPrinc == null) {
			tituloRes = new JLabel();
			tituloRes.setText("Restaurante \"Donde Sea\"");
			tituloRes.setHorizontalAlignment(SwingConstants.CENTER);
			tituloRes.setHorizontalTextPosition(SwingConstants.CENTER);
			tituloRes.setBackground(Color.black);
			tituloRes.setFont(new Font("Lucida Sans", Font.ITALIC, 24));
			jPanelPrinc = new JPanel();
			jPanelPrinc.setLayout(new BorderLayout());
			jPanelPrinc.add(tituloRes, BorderLayout.NORTH);
			jPanelPrinc.add(getPanelCentral(), BorderLayout.CENTER);
		}
		return jPanelPrinc;
	}

	/**
	 * This method initializes panelCentral
	 *
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelCentral() {
		if (panelCentral == null) {
			panelCentral = new JPanel();
			panelCentral.setLayout(new BorderLayout());
			panelCentral.add(getPanelBoton(), BorderLayout.CENTER);
			panelCentral.add(getPanelSalir(), BorderLayout.SOUTH);
		}
		return panelCentral;
	}

	/**
	 * This method initializes panelBoton
	 *
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelBoton() {
		if (panelBoton == null) {
			FlowLayout flowLayout = new FlowLayout();
			flowLayout.setVgap(37);
			flowLayout.setHgap(63);
			panelBoton = new JPanel();
			panelBoton.setLayout(flowLayout);
			panelBoton.add(getBotonCarta(), null);
			panelBoton.add(getBotonReserva(), null);
			panelBoton.add(getBotonFacturacion(), null);
			panelBoton.add(getBotonBalance(), null);
		}
		return panelBoton;
	}

	/**
	 * This method initializes botonCarta
	 *
	 * @return javax.swing.JButton
	 */
	private JButton getBotonCarta() {
		if (botonCarta == null) {
			botonCarta = new JButton();
			botonCarta.setText("Carta...");
			botonCarta.setToolTipText("Gestión de la carta.");
			botonCarta.setIcon(new ImageIcon(getClass().getResource("/iconos/table_edit.png")));
			botonCarta.setPreferredSize(new Dimension(130, 60));
			botonCarta.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {

					new CartaGrafica(frameRestaurante);


				}
			});
		}
		return botonCarta;
	}

	/**
	 * This method initializes botonReserva
	 *
	 * @return javax.swing.JButton
	 */
	private JButton getBotonReserva() {
		if (botonReserva == null) {
			botonReserva = new JButton();
			botonReserva.setPreferredSize(new Dimension(130, 60));
			botonReserva.setIcon(new ImageIcon(getClass().getResource("/iconos/user.png")));
			botonReserva.setText("Reservas...");
			botonReserva.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {

					new ReservaGrafica(frameRestaurante);

				}
			});
		}
		return botonReserva;
	}

	/**
	 * This method initializes botonFacturación
	 *
	 * @return javax.swing.JButton
	 */
	private JButton getBotonFacturacion() {
		if (botonFacturacion == null) {
			botonFacturacion = new JButton();
			botonFacturacion.setPreferredSize(new Dimension(130, 60));
			botonFacturacion.setIcon(new ImageIcon(getClass().getResource("/iconos/table.png")));
			botonFacturacion.setText("Facturación...");
		}
		return botonFacturacion;
	}

	/**
	 * This method initializes panelSalir
	 *
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelSalir() {
		if (panelSalir == null) {
			panelSalir = new JPanel();
			panelSalir.setLayout(new BoxLayout(getPanelSalir(), BoxLayout.X_AXIS));
			panelSalir.setPreferredSize(new Dimension(371, 100));
			panelSalir.add(getBotonSalir(), null);
			panelSalir.add(getScrollEstado(), null);
		}
		return panelSalir;
	}

	/**
	 * This method initializes botonSalir
	 *
	 * @return javax.swing.JButton
	 */
	private JButton getBotonSalir() {
		if (botonSalir == null) {
			botonSalir = new JButton();
			botonSalir.setHorizontalAlignment(SwingConstants.CENTER);
			botonSalir.setPreferredSize(new Dimension(135, 80));
			botonSalir.setComponentOrientation(ComponentOrientation.UNKNOWN);
			botonSalir.setIcon(new ImageIcon(getClass().getResource("/iconos/door_in.png")));
			botonSalir.setMnemonic(KeyEvent.VK_UNDEFINED);
			botonSalir.setText("Salir...");
			botonSalir.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.exit(1);
				}
			});
		}
		return botonSalir;
	}

	/**
	 * This method initializes textoEstado
	 *
	 * @return javax.swing.JTextArea
	 */
	private JTextArea getTextoEstado() {
		if (textoEstado == null) {
			textoEstado = new JTextArea();
			textoEstado.setColumns(19);
			textoEstado.setEditable(false);
			textoEstado.setPreferredSize(new Dimension(20, 10));
			textoEstado.setAutoscrolls(true);
		}
		return textoEstado;
	}







	/**
	 * This method initializes scrollEstado
	 *
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getScrollEstado() {
		if (scrollEstado == null) {
			scrollEstado = new JScrollPane();
			scrollEstado.setBorder(null);
			scrollEstado.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
			scrollEstado.setViewportBorder(BorderFactory.createTitledBorder(null, "Estado Conexión", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
			scrollEstado.setViewportView(getTextoEstado());
		}
		return scrollEstado;
	}







	/**
	 * This method initializes botonBalance	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBotonBalance() {
		if (botonBalance == null) {
			botonBalance = new JButton();
			botonBalance.setPreferredSize(new Dimension(130, 60));
			botonBalance.setIcon(new ImageIcon(getClass().getResource("/iconos/information.png")));
			botonBalance.setText("Balance...");
			
			botonBalance.addActionListener(new ActionListener(){

				public void actionPerformed(ActionEvent arg0) {
					// TODO Auto-generated method stub
					new BalanceGrafico(frameRestaurante).setVisible(true);
				}
				
			});
			
		}
		return botonBalance;
	}

}
